package com.ulook.lookplanet.util;


import java.util.Calendar;

/**
 * 描述：日期时间工具
 *
 * @author L1998
 * @data 2021/3/25
 */
public class TimeUtil {

    //取得当前时间的年月日 时分秒
    public static Calendar calendar = Calendar.getInstance();

    /**
     * 获取指定数据
     * @param type Calendar.TYPE
     * @return
     */
    public static int get(int type){
        return calendar.get(type);
    }

    /**
     * 获取当前年月日
     */
    public static String getCurrDate(){
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH);
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        return year + "-" + (month<10 ? "0"+month : month) + "-" + (day<10 ? "0"+day : day);
    }

    /**
     * 获取当前月份和日期
     */
    public static String getCurrMonthDay(){
        int month = calendar.get(Calendar.MONTH);
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        return (month<10 ? "0"+month : month) + "-" + (day<10 ? "0"+day : day);
    }

    /**
     * 获取当前时分秒
     */
    public static String getCurrTime(){
        int hour = calendar.get(Calendar.HOUR_OF_DAY);
        int minute = calendar.get(Calendar.MINUTE);
        int second = calendar.get(Calendar.SECOND);
        return (hour<10 ? "0"+hour : hour) + ":" + (minute<10 ? "0"+minute : minute) + ":" + (second<10 ? "0"+second : second);
    }

    /**
     * 获取当前小时和分钟
     */
    public static String getCurrHourMinute(){
        int hour = calendar.get(Calendar.HOUR_OF_DAY);
        int minute = calendar.get(Calendar.MINUTE);
        return (hour<10 ? "0"+hour : hour) + ":" + (minute<10 ? "0"+minute : minute);
    }

    /**
     * 获取当前日期和时间
     */
    public static String getCurrDateTime(){
        return getCurrDate() + " " + getCurrTime();
    }
}
